#ifndef WXSDRAWINGWINDOW_H
#define WXSDRAWINGWINDOW_H

#include <wx/scrolwin.h>
#include <wx/timer.h>
#include <wx/event.h>


class wxsDrawingWindow: public wxScrolledWindow {
  public:


    wxsDrawingWindow( wxWindow* Parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
                      const wxSize& size = wxDefaultSize, long style = wxHSCROLL | wxVSCROLL,
                      const wxString& name = _T( "wxsDrawingWindow" ) );


    virtual ~wxsDrawingWindow();


    const wxBitmap& GetBitmap() { return *m_Bitmap; }


    void BeforeContentChanged();


    void AfterContentChanged();


    void FastRepaint();


    inline void BlockFetch( bool Block = true ) { m_IsBlockFetch = Block; }

  protected:


    virtual void PaintExtra( wxDC* DC ) = 0;


    virtual void ScreenShootTaken() {}

  private:

    void OnPaint( wxPaintEvent& event );
    void OnEraseBack( wxEraseEvent& event );
    void OnFetchSequence( wxCommandEvent& event );
    void OnRefreshTimer( wxTimerEvent& event );

    virtual bool Destroy();


    void StartFetchingSequence();


    void FetchSequencePhase2();


    void FetchScreen();


    void HideChildren();


    void ShowChildren();


    bool NoNeedToRefetch();

    wxBitmap* m_Bitmap;             ///< \brief Bitmap with fetched window content (may be valid partially)
    bool m_IsBlockFetch;            ///< \brief Flag used to block fetching background (may be set by user)
    bool m_DuringFetch;             ///< \brief Set to true if we're during fetching sequence
    int m_DuringChangeCnt;          ///< \brief When >0, window's content is changed somewhere
    int m_LastSizeX, m_LastSizeY;   ///< \brief client size during last fetch
    int m_LastVirtX, m_LastVirtY;   ///< \brief virtual area shift relative to client area during last fetch
    bool m_WasContentChanged;       ///< \brief If there was a call to WasContentChanged from last fetch
    bool m_IsDestroyed;
    wxTimer m_RefreshTimer;
    DECLARE_EVENT_TABLE()
};

#endif
